﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;

namespace Room
{
    public class RoomNetBattle : RoomNetBase
    {
        public bool hasRegistSocket = false;

        public override void Enter()
        {
            NetAPI.CurrSceneId = (int)roomBase.GetServerType();
            RegistSocketHandler();
        }

        public override void Leave()
        {
            UnRegistSocketHandler();
        }

        public override void Pause()
        {
        }

        public override void Resume()
        {
        }

        public override void Init(RoomBase r)
        {
            base.Init(r);
            hasRegistSocket = false;
        }

        public override void Tick()
        {
        }

        public override void RegistSocketHandler()
        {
            if(!hasRegistSocket)
            {
                hasRegistSocket = true;
                NetAPI.RegistSocketHandler(OpDefine.SCPublicMessage, SCPublicMessage);
            }
        }

        public override void UnRegistSocketHandler()
        {
            if(hasRegistSocket)
            {
                hasRegistSocket = false;
                NetAPI.UnregisterSocketHandler(OpDefine.SCPublicMessage, SCPublicMessage);
            }
        }
    }
}